package com.oa.android;

import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

import com.baidu.mapapi.SDKInitializer;
import com.oa.android.server.LocateReceiver;

import org.xutils.DbManager;
import org.xutils.x;

import cn.jpush.android.api.JPushInterface;

/**
 * Created by zouqh on 2017-03-07.
 */

public class MyApplication extends Application {
    public static DbManager dbManager;
    public static Context mContext;

    @Override
    public void onCreate() {
        super.onCreate();
        JPushInterface.setDebugMode(true);
        JPushInterface.init(this);
        SDKInitializer.initialize(this);
        x.Ext.init(this);
        mContext=getApplicationContext();
        dbManager=initDaoConfig();
        initReceiver();
    }


    public  DbManager initDaoConfig() {
//        DbManager.DaoConfig daoConfig = new DbManager.DaoConfig()
//                .setDbName("xunxian")
//                .setAllowTransaction(true)
//                .setDbDir(new
//                        File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/CB/"))
//                .setDbVersion(1)
//                .setDbUpgradeListener(new DbManager.DbUpgradeListener() {
//                    @Override
//                    public void onUpgrade(DbManager db, int oldVersion, int newVersion) {
//                        // TODO: ...
//                        // db.addColumn(...);
//                        // db.dropTable(...);
//                        // ...
//                    }
//                });
        DbManager.DaoConfig daoConfig= new DbManager.DaoConfig();
        DbManager db = x.getDb(daoConfig);
        return db;
    }

    private void initReceiver() {
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_TIME_TICK);
        filter.addAction(Intent.ACTION_SCREEN_OFF);
        filter.addAction(Intent.ACTION_SCREEN_ON);
        LocateReceiver receiver = new LocateReceiver();
        registerReceiver(receiver, filter);
    }
    public static Context getContext() {
        return mContext;

}
}
